<?php

if (!defined('IN_IMBA')) exit('Access Denied.');

interface Database
{
	public function __construct($configFile);
	public function __destruct();

	/**
	 * @name destroy_conn
	 * @description Destroy a specified connection to the database, and destroy all result set related to it cascade.
	 * @parameter int $id: specify which connection to destroy.
	 * @return void
	 * */
	public function destroy_conn($id);

	/**
	 * @name query
	 * @description Accept a SQL statement and execute it, save the result set if exist to the result set array.
	 * @parameter
	 *   string $sql: The SQL statement to execute.
	 *   string $query: The identifier of the result set, leave it empty if you do not want to save it.
	 * @return void
	 * */
	public function query($sql, $query = '');

	/**
	 * @name free_result
	 * @description Free a specified result set of the current connection. The result sets which does not exist or belongs to other connections will be ignored.
	 * @parameter
	 *   string $query: Specify which result set to free.
	 * @return bool: true if success and false if failure.
	 * */
	public function free_result($query);

	/**
	 * @name switch_conn
	 * @description Switch to the specified connection.
	 * @parameter
	 *   int $id: The identifier of the connection object to switch to.
	 * @return bool: true if success and false if failure.
	 * */
	public function switch_conn($id);

	/**
	 * @name create_new_conn
	 * @description Create a new database connection object.
	 * @parameter
	 *   string $configFile: Specify the config file which is used to initialize the database connection object.
	 * @return bool: true if success and false if failure.
	 * */
	public function create_new_conn($configFile);

	/**
	 * @name fetch_array
	 * @description Fetch a result row as an associative, a numeric array, or both.
	 * @parameter
	 *   string $query: Determine which result set to operate on.
	 *   int $result_type: Determine the type of the result, accept MYSQLI_NUM, MYSQLI_ASSOC, MYSQLI_BOTH
	 * @return int: The identifier of the latest created connection object.
	 * */
	public function fetch_array($query, $result_type = MYSQLI_ASSOC);

	/**
	 * @name num_rows
	 * @description Return the number of rows of the specified result set of the current connection.
	 * @parameter
	 *   string $query: Determine which result set to operate on.
	 * @return mixed: The result array to be returned.
	 * */
	public function num_rows($query);

	/**
	 * @name last_insert_id
	 * @description Return the value of last affected auto increment value in the database.
	 * @parameter void
	 * @return int: The value of last affected auto increment value in the database.
	 * */
	public function last_insert_id();
}

?>